//
//  CityViewController.m
//  09-homework-province-city
//
//  Created by 王道林 on 16/7/26.
//  Copyright © 2016年 王道林. All rights reserved.
//

#import "CityViewController.h"
#import "TownViewController.h"
@interface CityViewController ()<UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, strong) UITableView *tableView;
@end

@implementation CityViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self createSubView];
}

- (void)createSubView
{
    _tableView = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStylePlain];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    [self.view addSubview:_tableView];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _marrCity.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"wang"];
    
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"wang"];
    }
    NSString *province = _marrCity[indexPath.row][@"cityName"];
    NSArray *arr = [province componentsSeparatedByString:@" "];
    cell.textLabel.text = [arr objectAtIndex:2];
    cell.detailTextLabel.text = [arr lastObject];
    return cell;

}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    TownViewController *townVc = [[TownViewController alloc] init];
    NSMutableArray *marr = _marrCity[indexPath.row][@"town"];
    townVc.marrTown = marr;
    [self.navigationController pushViewController:townVc animated:YES];
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
